<template>
    <div class="tree">
      <ul>
        <li>
          <span><i class="fa fa-minus-circle"></i>{{ data.deptName }}</span>
          <tree-node :data="data" :selectedId="selectedId" @deptDetails="getUserList"></tree-node>
        </li>
      </ul>
   </div>
</template>

<script>
  import treeNode from './tree-node.vue'
  export default {
    name: 'tree',
    components: {
      treeNode
    },
    props: ["data"],
    data() {
      return {
        selectedId: null
      };
    },
    created() {},
    mounted() {
      this.bus.$on('selectedId', (selectedId) => {
        this.selectedId = selectedId;
      })
    },
    methods: {
      getUserList(item) {
        this.$emit('refresh',item)
      },
      
    }
  }
</script>

<style scoped>
  ul, li {
    list-style-type: none;
  }

  .tree {
    display: block;
    position: relative;
    padding: 5px 15px;
  }

  .tree span {
    display: inline-block;
    box-sizing: border-box;
    height: 30px;
    line-height: 28px;
    min-width: 60px;
    text-align: center;
    color: #888;
    border: 1px solid #ddd;
    border-radius: 5px;
    padding: 0 8px;
  }

  .tree ul {
    position: relative;
    padding-left: 60px;
    margin: 0;
  }

  .tree ul>li {
    position: relative;
    padding: 5px 0;
  }

  .tree>ul {
    padding: 0;
    margin: 0;
  }

  /** 水平方向连线 */
  .tree>ul ul>li:after {
    content: ' ';
    position: absolute;
    top: 20px;
    left: -45px;
    width: 45px;
    border: none;
    border-top: 1px solid #ddd;
  }

  /** 垂直方向连线 */
 .tree ul>li:not(:last-child):before {
    content: ' ';
    position: absolute;
    top: 0;
    left: -45px;
    height: 100%;
    border: none;
    border-left: 1px solid #ddd;
  }
  .tree ul>li:last-child:before {
    content: ' ';
    position: absolute;
    top: 0;
    left: -45px;
    height: 20px;
    border: none;
    border-left: 1px solid #ddd;
  }

  /** 控制鼠标移上去的颜色 */
  .tree span:hover,
  .tree span:hover+ul span {
    color: #fff;
    background-color: orange;
  }

  .tree span:hover,
  .tree span:hover+ul span,
  .tree span:hover+ul li:before,
  .tree span:hover+ul li:after {
    border-color: orange;
  }

  /** 折叠图标 */
  .tree .fa:before {
    margin-right: 5px;
  }

  .tree .fa-minus-circle,
  .tree .fa-plus-circle {
    cursor: pointer;
  }
</style>
